<!-- 
@name: 积分红包
-->
<template>
	<div id="BankingBusinessList" class="page">
		<van-tabs v-model="searchData.status" color='#FFCE17' @click="onClick">
			<van-tab title="未领取" name="INIT"></van-tab>
			<van-tab title="已领取" name="PAID"></van-tab>
		</van-tabs>
		<div class="content-wrap">
			<div class="diy-area">
				<div class="like">
					<div class="type2" v-if="listModel" ref='type2Scorll' id='type2Scorll'>
						<van-list v-model="loading" offset='0' :finished="finished" finished-text="" @load="onLoad">
							<div :class="goodsItem.status != 'INIT'?'itemImg_yes':'itemImg_not'" class="item flex-between flex-center" v-for="(goodsItem, goodsIndex) in likeList" :key="goodsIndex">
								<div style="width:4rem">
									<div class="text1">{{goodsItem.pv}}<span class="text2">积分</span> </div>
								</div>
								<van-button class="button" @click="revRed_centre(goodsItem)">{{goodsItem.status== "INIT"?'领取':'已领取'}}</van-button>

							</div>
						</van-list>

					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
export default {
	name: 'app',
	components: {},
	data() {
		return {
			searchValue: '',
			searchTypeIndex: '',
			getGtypeList: [],
			listModel: true, //true 列表模式 false 大图模式
			searchTypeList: [
				{ value: '销量最高', pkey: 'XS' },
				{ value: '距离最近', pkey: 'NEAR' },
				{ value: '评分最高', pkey: 'RATE' },
			],
			searchData: {
				page: 0,
				pagesize: 9999,
				status: 'INIT', //INIT(0, "初始"),PAID(1, "已领取"),
			},
			likeList: [],
			activeName: '',
			loading: false,
			finished: false,
		};
	},

	created() {
		if (this.$route.query.pkey) {
			//跳转过来的分类pkey
			this.activeName = Number(this.$route.query.pkey);
		}
		this.getGtype_goods();
	},
	methods: {
		//切换标签
		onClick() {
		

			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		get_member() {
			var params = {};
			this.$myApi.get_member(params).then((res) => {
				if (res.code == 0) {
					this.$store.dispatch('SET_USERINFO', res.result);
				} else {
				}
			});
		},
		revRed_centre(item) {
			if (item.status != 'INIT') {
				return;
			}
			var params = {
				pkey: item.pkey,
			};
			this.$myApi.revRed_centre(params).then((res) => {
				if (res.code == 0) {
					this.$notify({ type: 'success', message: '领取成功' });
					this.onClick();
					this.get_member();
				} else {
				}
			});
		},
		sortChange(pkey) {
			this.searchData.sortType = pkey;
			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		onLoad() {
			console.log('触底');
			this.getData();
		},
		onClick() {
			this.clearSearch();
			this.finished = true;
			this.getData(true);
		},
		getGtype_goods() {
			this.$myApi.getGtype_goods().then((res) => {
				if (res.code == 0) {
					var arr = [{ name: '全部', pkey: '' }, ...res.result];
					this.getGtypeList = arr;
				} else {
				}
			});
		},
		getData(finished) {
			// finished 避免清空列表出发刷新
			var params = this.searchData;
			params.gtype = this.activeName;
			this.$myApi.redPack_centre(params).then((res) => {
				if (res.code == 0) {
					this.likeList = [...this.likeList, ...res.result];
					this.loading = false;
					this.searchData.page++;
					if (finished) {
						this.finished = false;
					}
					if (true) {//此接口没有分页
						this.finished = true;
					}
					// if (res.result.length < this.searchData.pagesize) {
					// 	this.finished = true;
					// }
				} else {
				}
			});
		},
		clearSearch() {
			this.likeList = [];
			this.searchData.page = 0;
			this.searchData.pagesize = 5;
			this.finished = false;
		},
		onSearch(e) {
			console.log(e);
			this.clearSearch();
			this.searchData.title = e;
			this.finished = true;
			this.getData(true);
		},
		onCancel() {},
	},
};
</script>
<style lang="less" scoped>
#BankingBusinessList {
	padding-left: 0rem;
	padding-right: 0rem;
	min-height: 100vh;
	background-color: #fafafa;
	padding-bottom: 0;
	.van-swipe__indicators {
		bottom: 25px;
	}
	.van-search__content {
		border-radius: 20px;
	}
	.searchWrap {
		width: 100%;
	}
	.searchHistory {
		padding: 0.25rem;
		background-color: #fff;
		img {
			height: 0.28rem;
			width: 0.32rem;
		}
		.text1 {
			font-size: 0.28rem;
			font-weight: bold;
			color: #333333;
			margin-bottom: 0.2rem;
		}
		.text2 {
			background: #f5f5f5;
			border-radius: 5px;
			padding: 0.16rem 0.3rem;
			margin-right: 0.12rem;
			margin-bottom: 0.12rem;
			white-space: nowrap;
			display: inline-block;
			font-size: 0.24rem;
			color: #666666;
		}
		.text3 {
			.text2();
			color: #999999;
		}
	}
	.content-wrap {
		width: 100%;
		height: auto;
		.diy-area {
			// background-color: #fff;
			position: relative;
			background-color: inherit;

			img {
				vertical-align: top;
			}

			.banner {
				.bannerImg {
					height: 4rem;
					width: 100%;
				}
			}
			.br {
				height: 0.2rem;
				width: 100%;
				background: #fafafa;
			}
			.likeTitle {
				font-size: 0.32rem;
				font-family: PingFang SC;
				font-weight: bold;
				color: #000000;
				margin-bottom: 0.24rem;
				text-align: center;
			}
			.like {
				padding: 0.25rem;

				// height: calc(100vh - 46px - 0.5rem);
				height: 100vh;
				position: relative;
				box-sizing: border-box;
				border-radius: 10px;

				.type2 {
					width: 100%;
					overflow-x: scroll;
					height: 100%;
					padding-bottom: 1rem;
					img {
						height: 1.1rem;
						width: 1.1rem;
						margin-right: 0.24rem;
						border-radius: 5px;
					}
					.itemImg_yes {
						background: #fff url('../../assets/images/ylq.png') top
							center no-repeat;
						background-size: 100% auto;
						.button {
							background: #ffffff;
							border-radius: 20px;
							font-size: 0.26rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #999999;
							padding: 0.1rem 0.34rem;
							height: auto;
							margin-right: 0.2rem;
						}
						.text1 {
							font-size: 0.64rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #999999;
						}
						.text2 {
							font-size: 0.32rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #999999;
							margin-left: 0.2rem;
						}
					}
					.itemImg_not {
						background: #fff url('../../assets/images/dlq.png') top
							center no-repeat;
						background-size: 100% auto;
						.button {
							background: #ffffff;
							border-radius: 20px;
							font-size: 0.26rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
							padding: 0.1rem 0.34rem;
							height: auto;
							margin-right: 0.3rem;
						}
						.text1 {
							font-size: 0.64rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
						}
						.text2 {
							font-size: 0.32rem;
							font-family: PingFang SC;
							font-weight: bold;
							color: #D95954;
							margin-left: 0.2rem;
						}
					}
					.item {
						width: 7rem;
						height: 1.6rem;
						padding: 0.2rem;
						margin-bottom: 8px;

						border-radius: 10px;
					}
				}
			}
			.iconWrap {
				position: relative;
				padding-bottom: 0.55rem;
				border-radius: 20px 20px 0 0;
				top: -0.3rem;
				// margin-top: -0.4rem;
				background-color: #fafafa;
				z-index: 999;
				display: grid;
				grid-template-columns: repeat(4, 25%);
				.iconImg {
					width: 0.8rem;
					height: 0.8rem;
					margin-bottom: 0.12rem;
				}
				.item {
					-webkit-box-flex: 1;
					flex: 1;
					margin-top: 0.3rem;
					font-size: 0.24rem;
					text-align: center;
				}
			}
		}
	}
}
</style>
<style lang="less" scoped>
/deep/.van-search .van-cell {
	padding-top: 0.2rem;
	padding-bottom: 0.2rem;
	font-size: 0.28rem;
}
/deep/.van-tab {
	// flex: 0 1 auto;
	// width: 1rem;
	font-size: 0.3rem;
}
/deep/.van-tab--active {
	font-weight: bold;
	font-size: 0.32rem;
}
</style>